package day018.thread.demo7;

public class ConsumerTask implements Runnable {
    @Override
    public void run() {
        while (true) {
            synchronized (Resource.LOCK) {
                if (Resource.num == 0) {
                    try {
                        System.out.println(Thread.currentThread().getName() + " 发现没有食物，等待中~~");
                        Resource.LOCK.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    System.out.println(Thread.currentThread().getName() + " 发现食物，开始消费" + Resource.num);
                    Resource.num--;
                    Resource.LOCK.notify();
                }
            }
        }
    }
}
